package vip.xls8z.simple.autoconfigure;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Configurable;
import org.springframework.boot.autoconfigure.condition.*;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import vip.xls8z.simple.config.SimpleProperties;
import vip.xls8z.simple.service.SimpleService;

@Configurable // 标记配置类
@ConditionalOnClass({SimpleService.class}) // 当有SimpleService类才加载
@EnableConfigurationProperties(SimpleProperties.class) // 将application.properties中配置与SimpleProperties对应并生成Bean
public class SimpleAutoConfiguration {

    @Bean
    @ConditionalOnMissingBean({SimpleService.class})
    public SimpleService simpleService(SimpleProperties simpleProperties) {
        return new SimpleService(simpleProperties);
    }
}
